<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *兑奖管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	} 
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_yousetli_exchange',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$member=pdo_get('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['mid']));
			$act=pdo_get('jy_yousetli_act',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['actid']));
			$play=pdo_get('jy_yousetli_player',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['playid']));
			$coupon=pdo_get('jy_weishop_coupon',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['couponid']));

			$item['createtime']=date('y-m-d h:i:s',$item['createtime']);
			$item['shenhetime']=date('y-m-d h:i:s',$item['shenhetime']);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'审核列表'),
		),
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'title','title'=>'活动名称','type'=>'string'),
			array('type'=>'img_string','title'=>'时间',
			'data'=>array(
				array('title'=>'申请时间：','name'=>'createtime'),
				array('title'=>'审核时间：','name'=>'shenhetime'),
				)
			),
			array('name'=>'total','title'=>'库存','type'=>'string'),
		)),
		'search'=>array(
			array('name'=>'title','width'=>15,'title'=>'活动名称','type'=>'string',),
			array('name'=>'status','width'=>15,'title'=>'状态','type'=>'radio','options'=>'status'),
		)
	);
	$return['status']=array('0'=>'待审核','1'=>'审核通过','2'=>'审核不通过');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_yousetli_exchange',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}
if($_RQ['op']=='set'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择要编辑的活动！','error');
	}
	$post=get_postdata();
	if(isset($post['status'])){
		pdo_update('jy_yousetli_exchange',array('status'=>intval($post['status'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('操作成功！');
}
